# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/13 下午5:45
 @Author  : tgy
 
"""

# MyType = type('MyType',{},{})
class MyType(type):
    """
    MyType的 __init__ 和 __new__ 是在 type的 __call__中调用的，因为
    MyType = type('MyType',{},)
    """

    def __init__(self, *args, **kwargs):
        print(self)
        print(args)
        print(kwargs)
        super().__init__(*args, **kwargs)

    # @staticmethod
    def __new__(cls, *args, **kwargs):
        ...
        print(cls)
        return super().__new__(cls, *args, **kwargs)

    def __call__(self, *args, **kwargs):
        ...
        print(self)
        obj = self.__new__(self)
        self.__init__(obj, *args, **kwargs)
        return obj

# Person = MyType(class_name,super,{})
class Person(object, metaclass=MyType):
    ...
    name = 'zhangsan'

    def run(self):
        print('222')

    def __call__(self, *args, **kwargs):
        ...
        # return self()

    def __new__(cls, *args, **kwargs):
       return super().__new__(cls)


if __name__ == '__main__':
    ...
    # print(Person())
    person = Person()
    print(person.name)
    person.run()
